
const dal = require("./dal");

let obj = {
    async videoIsExist (url) {
        let video = await dal.video();
        if (video.find({url: url.toLocaleLowerCase()}).count() > 0) {
            return true;
        }
        else {
            return false;
        }
    },
    async insertVideo (userId, workId, url, buf) {
        let video = await dal.video();
        video.insert({
            userId: userId,
            workId: workId,
            url: url.toLocaleLowerCase(),
            buf: buf,
            insertTime: new Date()
        });
    },
    async imageIsExist (url) {
        let image = await dal.image();
        if (await image.find({url: url.toLocaleLowerCase()}).count() > 0) {
            return true;
        }
        else {
            return false;
        }
    },
    async insertImage (userId, workId, head, url, buf) {
        let image = await dal.image();
        await image.insert({
            userId: userId,
            workId: workId,
            url: url.toLocaleLowerCase(),
            buf: buf,
            insertTime: new Date()
        });
    },
    async getImage (workId) {
        let image = await dal.image();
        return await image.findOne({workId: workId});
    }
};

module.exports = obj;